from __future__ import print_function

import time
import fastreport_cloud_sdk
from fastreport_cloud_sdk.rest import ApiException, RESTResponse
from pprint import pprint
import shutil

## Setting up the configuration for accessing fastreport.cloud

configuration = fastreport_cloud_sdk.Configuration(
    host = "https://fastreport.cloud",
    username = 'apikey',
    password = '????????????????????????????????????????????????????'
)

report = "77u/PD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0idXRmLTgiPz4NCjxSZXBvcnQgU2NyaXB0TGFuZ3VhZ2U9IkNTaGFycCIgUmVwb3J0SW5mby5DcmVhdGVkPSIwMS8xMS8yMDE3IDE5OjEwOjIzIiBSZXBvcnRJbmZvLk1vZGlmaWVkPSIwMy8yNC8yMDE3IDE3OjE0OjMxIiBSZXBvcnRJbmZvLkNyZWF0b3JWZXJzaW9uPSIxLjAuMC4wIj4NCiAgPFN0eWxlcz4NCiAgICA8U3R5bGUgTmFtZT0iU3R5bGUxIiBCb3JkZXIuU2hhZG93PSJ0cnVlIiBGaWxsLkNvbG9yPSJPcmFuZ2VSZWQiIEZvbnQ9IkFyaWFsIE5hcnJvdywgMzZwdCwgc3R5bGU9Qm9sZCwgSXRhbGljIiBBcHBseUJvcmRlcj0iZmFsc2UiIEFwcGx5RmlsbD0iZmFsc2UiLz4NCiAgICA8U3R5bGUgTmFtZT0iU3R5bGUyIiBUZXh0RmlsbC5Db2xvcj0iV2hpdGUiIEZvbnQ9IkFyaWFsLCAyNnB0LCBzdHlsZT1Cb2xkIiBBcHBseUJvcmRlcj0iZmFsc2UiIEFwcGx5RmlsbD0iZmFsc2UiLz4NCiAgICA8U3R5bGUgTmFtZT0iU3R5bGUzIiBGb250PSJHZW9yZ2lhLCAyNHB0IiBBcHBseUJvcmRlcj0iZmFsc2UiIEFwcGx5RmlsbD0iZmFsc2UiLz4NCiAgPC9TdHlsZXM+DQogIDxEaWN0aW9uYXJ5Lz4NCiAgPFJlcG9ydFBhZ2UgTmFtZT0iUGFnZTEiIExhbmRzY2FwZT0idHJ1ZSIgUGFwZ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D0iMTc5LjU1IiBUb3A9IjcwOC43NSIgV2lkdGg9IjE0OC43NSIgSGVpZ2h0PSIyOC4zNSIgU2hvd1RleHQ9ImZhbHNlIiBCYXJjb2RlPSJQaGFybWFjb2RlIiBCYXJjb2RlLlF1aWV0Wm9uZT0idHJ1ZSIvPg0KICAgIDwvRGF0YUJhbmQ+DQogIDwvUmVwb3J0UGFnZT4NCjwvUmVwb3J0Pg0K";

with fastreport_cloud_sdk.ApiClient(configuration) as api_client:
    templates = fastreport_cloud_sdk.TemplatesApi(api_client)
    exports = fastreport_cloud_sdk.ExportsApi(api_client)
    downloads = fastreport_cloud_sdk.DownloadApi(api_client)
    # Get root folder
    root_folder = templates.template_folders_get_root_folder()
    # Upload a new file
    file_vm = fastreport_cloud_sdk.TemplateCreateVM(
        content = report,
        name = "python.frx"
    )
    file = templates.templates_upload_file(root_folder.id, file_vm=file_vm)
    export_root = exports.export_folders_get_root_folder()
    export_task = fastreport_cloud_sdk.ExportTemplateTaskVM(
        folder_id = export_root.id,
        file_name = "python.pdf",
        pages_count = 999,
        format = "Pdf"
    )
    export = templates.templates_export(file.id, export_task=export_task)
    export_id=export.id;
    while export.status != "Success":
        pprint(export.status);
        time.sleep(1)
        export = exports.exports_get_file(export_id);
    pdf = downloads.download_get_export(export_id)
    shutil.copyfile(pdf, "python.pdf")
